﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Web.SessionState;

namespace ShopPowerTemplate.Presentation.Mvc.Test
{
    public class WebHelper
    {
        internal static T GetMockedController<T>(T controller) where T : Controller
        {
            SetContext();
            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new HttpContextWrapper(HttpContext.Current)
            };
            return controller;
        }
        
        static void SetContext()
        {
            if (HttpContext.Current == null)
            {
                HttpContext.Current = new HttpContext(
                    new HttpRequest("", "http://tempuri.org", ""),
                    new HttpResponse(new StreamWriter(new MemoryStream()))
                    );
                SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, new TestSession());
            }
        }
    }
}
